﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _210624
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {


            protected void Button1_Click(object sender, EventArgs e)
            {
                string name = UserName.Text;
                string pwd = Password.Text;
                string email = Email.Text;
                string intro = Intro.Text;


                string constr = "server=.;uid=sa;pwd=123456;database=Student_db";

                SqlConnection con = new SqlConnection(constr);

                con.Open();

                string sql = "insert into StudentInfo (stu_name,password,email,intro) values (@name,@pwd,@email,@intro)";
                SqlParameter[] pars =
                {
                new SqlParameter("@name",name),
                new SqlParameter("@pwd",pwd),
                new SqlParameter("@email",email),
                new SqlParameter("@intro",intro)
            };
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.AddRange(pars);

                int result = cmd.ExecuteNonQuery();//返回 影响行数，如果返回-1说明执行失败
                if (result > 0)
                {
                    Literal1.Text = "注册成功！<a href='WebForm1.aspx'>去登陆</a>";
                }
                else
                {
                    Literal1.Text = "注册失败！";
                }



            }
        }
    }
}